package cube.io.file;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

import cube.data.util.DataUtil;

/**
 * 文件输入处理
 * 
 * @author abiao
 */
public abstract class FileInputHandler<T> extends
        FileHandler<FileInputStream, T> {

    /**
     * 文件输入处理
     */
    public FileInputHandler(String fileName) {
        super(fileName);
    }

    /**
     * 初始化流
     */
    public FileInputStream init(String fileName) {
        FileInputStream fis = null;
        try {
            fis = new FileInputStream(fileName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
        return fis;
    }

    /**
     * 读取文件字节数组
     */
    protected byte[] read(FileInputStream fis, final int size)
            throws IOException {
        byte[] buff = new byte[DataUtil.min(size, fis.available())];
        fis.read(buff);
        return buff;
    }
}
